package com.foreknow.test;

public class Manager {
    private Employee[] emps;
    private int count;

    public Manager() {
        emps = new Employee[5];
    }

    /**
     * 添加员工信息
     * @param emp
     */
    public void save(Employee emp) {
        //1. 判断emp是否为空
        if(emp != null) {
            //2. 如果emp不为空还要判断添加的元素不能超出数组的长度
            if(count < 5) {
                //3. 要将emp保存到emps数组中并输出是否添加成功
                emps[count] = emp;
                count++;
                System.out.println("添加成功......");
            }else {
                System.out.println("添加失败......");
            }
        }
    }

    public static void main(String[] args) {
        Manager manager = new Manager();
        Employee e1 = new Employee();
        e1.setEid("10000");
        e1.setName("fender1");
        Employee e2 = new Employee();
        e2.setEid("10001");
        e2.setName("fender2");
        Employee e3 = new Employee();
        e3.setEid("10002");
        e3.setName("fender3");
        Employee e4 = new Employee();
        e4.setEid("10003");
        e4.setName("fender4");
        Employee e5 = new Employee();
        e5.setEid("10004");
        e5.setName("fender5");
        manager.save(e1);
        manager.save(e2);
        manager.save(e3);
        manager.save(e4);
        manager.save(e5);

        //调用根据id查询员工信息的方法
        Employee xxx = manager.getQueryById("10002");
        System.out.println(xxx.getEid()+"---"+xxx.getName());

        //update
        Employee employee = manager.update(xxx);
        System.out.println(employee.getName());

    }



    /**
     * 根据id查询某个员工
     * @param id
     * @return
     */
    public Employee getQueryById(String id) {
        Employee employees = null;
        //1. 对emps数组遍历，每遍历一次用id与对象中的id比较 id.equals(数组中员工对象的id)
        for(int i = 0;i<emps.length;i++){
            if(id.equals(emps[i].getEid())) {
                employees = emps[i];
                break;
            }
        }
        return employees;
    }

    /**
     * 修改员工信息
     * @param employee
     * @return
     */
    public Employee update(Employee employee) {
        employee.setName("xxx");
        return employee;
    }

    /**
     * 查询所有用户信息
     * @return
     */
    public Employee[] getAll() {
        return null;
    }





}
